﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using HellCook.Model;
using HellCook.Business;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace HellCook.WinApp_WPF.Ingrediente_Administrador.IngredientFunctionality
{
    /// <summary>
    /// Lógica de interacción para ModificarIngrediente.xaml
    /// </summary>
    public partial class ModificarIngrediente : Window
    {
        public int codigo;
        public ModificarIngrediente(Ingrediente Item)
        {
            InitializeComponent();
            IniciarValores(Item);            
        }


        public void IniciarValores(Ingrediente item)
        {
            this.comboBox_MeasuredType.Items.Add("Unidad");
            this.comboBox_MeasuredType.Items.Add("Kilo");
            this.comboBox_MeasuredType.Items.Add("Gramos");
            this.comboBox_MeasuredType.Items.Add("Litro");
            this.comboBox_MeasuredType.Items.Add("CC");
            this.comboBox_MeasuredType.Items.Add("Libra");
            this.comboBox_MeasuredType.SelectedIndex = 0;

            this.comboBox_FoodGroup.Items.Add("Fruta");
            this.comboBox_FoodGroup.Items.Add("Vegetal");
            this.comboBox_FoodGroup.Items.Add("Masa");
            this.comboBox_FoodGroup.Items.Add("Leche_Y_Derivados");
            this.comboBox_FoodGroup.Items.Add("Cereal");
            this.comboBox_FoodGroup.Items.Add("Legumbres");
            this.comboBox_FoodGroup.Items.Add("Huevos");
            this.comboBox_FoodGroup.Items.Add("Azucares_Y_Grasas");
            this.comboBox_FoodGroup.Items.Add("Pescado");
            this.comboBox_FoodGroup.Items.Add("Enlatados");
            this.comboBox_FoodGroup.Items.Add("Liquido");
            this.comboBox_FoodGroup.Items.Add("Carnes");
            this.comboBox_FoodGroup.Items.Add("Otros");
            
            for (int Ptr = 0; Ptr < this.comboBox_FoodGroup.Items.Count; Ptr++)
            {
                if (String.Equals(this.comboBox_FoodGroup.Items[Ptr].ToString(), item.Grupo_Alimenticio))
                {
                    comboBox_FoodGroup.SelectedIndex = Ptr;
                }
            }
            
            for (int Ptr = 0; Ptr < this.comboBox_MeasuredType.Items.Count; Ptr++)
            {
                if (String.Equals(this.comboBox_MeasuredType.Items[Ptr].ToString(), item.Tipo_Medida))
                {
                    comboBox_MeasuredType.SelectedIndex = Ptr;
                }
            }

            if (item.Cantidad_Maxima > 0)
            {
                this.CheckBox_IngredienteMensual.IsChecked = true;
                this.TextBox_CantidadMaxima.Text = item.Cantidad_Maxima.ToString();
            }
            else
            {
                this.CheckBox_IngredienteMensual.IsChecked = false;
                this.TextBox_CantidadMaxima.Text = "";
                this.TextBox_CantidadMaxima.IsEnabled = false;
            }
            
            textBox_NameIngredient.Text = item.Nombre_Ingrediente;
            textBox_Quantity.Text = item.Cantidad.ToString();                        
            codigo = item.Codigo;
        }

        private void button_Add_Click(object sender, RoutedEventArgs e)
        {
            string Message = HellCook.Business.Ingrediente_Registro.ModificarIngrediente(codigo, this.textBox_NameIngredient.Text, this.textBox_Quantity.Text, this.comboBox_MeasuredType.SelectedItem.ToString(), this.comboBox_FoodGroup.SelectedItem.ToString(), this.calendar_ExpirationDate.SelectedDate.ToString(), this.TextBox_CantidadMaxima.Text);
            MessageBoxResult result;
            result = MessageBox.Show(Message + " ¿Desea continuar?", "Mensaje", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.No)
            {
                this.Close();
            }
        }

        private void CheckBox_IngredienteMensual_Checked(object sender, RoutedEventArgs e)
        {
            if (this.CheckBox_IngredienteMensual.IsChecked.Value == true)
            {
                this.TextBox_CantidadMaxima.IsEnabled = true;
            }
            else
            {
                this.TextBox_CantidadMaxima.IsEnabled = false;
            }
        }

        private void button_Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        
    }
}
